<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <script type="text/javascript" src="../js/vue.js"></script>
  <title>列表渲染</title>
</head>
<body>
  <div id="root">
    <h2>列表过滤</h2>
    <hr>
    <input type="text" v-model="inputKey" placeholder="检索姓名">
    <div>
      <ul v-for="p of filePersion" :key="p.id">
        <li>{{p.name}} ，年龄：{{p.age}}</li>
      </ul>
    </div>
  </div>
  <script type="text/javascript">
     new Vue({
      el: '#root', 
      data: { 
        inputKey: '',
        persion: [
          {id:'sk9G2O01avD',name:'张三',age:'12'},
          {id:'k8F4Dl7m',name:'李四',age:'34'},
          {id:'1Ff3lm0G',name:'李六',age:'54'},
          {id:'sf3Pd94pf7za',name:'张九',age:'12'},
          {id:'oB5vA0Qmm1p',name:'杰克',age:'22'}
        ],
        filePersion : []
      },
      watch: {
        inputKey: {
          immediate: true,
          handler: function (val, oldVal) { 
            this.filePersion = this.persion.filter((p)=>{
              return p.name.indexOf(val) >= 0
            })
          }
        }
      },
    })
  </script>
</body>
</html>